<?php
namespace app\api\controller;
use think\Controller;
use think\Request;
use think\Config;

class Upload extends Controller
{
    public function index()
    {

	    $file = request()->file('file');
	    if($file){
	    	$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
	    	if($info){
	            // 成功上传后 获取上传信息
	            $data = [
	            	'image'=>Config::get('live.host').'uploads/'.$info->getSaveName()
	            ];
	            return json_encode(['errorCode'=>0,'msg'=>'upload success','data'=>$data]);
	        }else{
	            // 上传失败获取错误信息
	            return json_encode(['errorCode'=>'1000','msg'=>$file->getError()]);
	        }
	    }
	    
    }
}
